﻿using System;
using System.Collections;

namespace GenericsExample
{


    class MyCustomList<T> : IEnumerable
    {
        private T[] innerArray;
        public int Count { get; private set; }

        public T this[int index]
        {
            get { return innerArray[index]; }
        }

        public int Capacity
        {
            get { return innerArray.Length; }
        }

        public MyCustomList()
        {
            innerArray = new T[4];
        }

        public void Add(T value)
        {
            if (Count == Capacity)
            {
                T[] newList = new T[Capacity*2];
                Array.Copy(innerArray, newList, Capacity);
                innerArray = newList;
            }
            innerArray[Count++] = value;
        }

        public IEnumerator GetEnumerator()
        {
            return innerArray.GetEnumerator();
        }

    }

}